/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.compare.VehicleInfoView');
(function ()
{
	
	var VFORMAT = net.autodata.compare.data.Format;
	
	var QTIP = '<span ext:qtip="{0}">{1}</span>';
	
	/**
	 * This view is used to define how a VehicleInfoPanel is rendered
	 * @class VehicleInfoView
	 * @extends net.autodata.AbstractView
	 * @namespace net.autodata.compare
	 */
	var View = Ext.extend(net.autodata.AbstractView, {
		
		/**
		 * @property templates
		 * @type Object
		 */
		templates: undefined,
		
		//override the Abstract constructor to allow this object to be created
		constructor: function ()
		{
			View.superclass.ctor.apply(this, arguments);
		},
		
		/**
		 * @method initTemplates
		 */
		initTemplates: function ()
		{
			var ts = this.templates || {};
			
			var panel = this.component;
			
			if (!ts.mainTpl) {
				ts.mainTpl = new Ext.XTemplate(
					'<h5>{[this.ym(values)]}</h5>',
					'<h5>{[this.mt(values)]}</h5>',
					'<h6>{[ASC.message(\'net.autodata.vehicle.msrp\')]} {[this.currency(values.msrp)]}</h6>',
					{
						compile: true,
						disableFormats: true,
						
						ym: function (values)
						{
							return VFORMAT.ym(values);
						},
						
						mt: function (values)
						{
							var str = VFORMAT.mt(values);
							var max = panel.descriptionMaxLength || 0;
							if (max && str.length > max) {
								return String.format(QTIP, str, Ext.util.Format.ellipsis(str, panel.descriptionMaxLength));
							}
							
							return str;
						},
						
						currency: function (value)
						{
							return value ? ASC.util.formatCurrency(value, 0) : '';
						}						
					}
				);				
			}
			
			this.templates = ts;
			
			View.superclass.initTemplates.apply(this, arguments);
		},
		
		/**
		 * @method render
		 */
		render: function ()
		{
			View.superclass.render.apply(this, arguments);
			
			var panel = this.component;
			if (!panel) {
				return;
			}
			var body = this.component.el;
			this.templates.mainTpl.overwrite(body.dom, panel.getData()||{});
		}		
	});
	
	net.autodata.compare.VehicleInfoView = View;
})();